<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label label-required">时间</label>
                <div class="layui-input-block">
                    <input name="time" data-date-input="date" value='{$vo.time|default=""}' required placeholder="请选择时间" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">水印照片</label>
            <div class="layui-input-block">
                <label class="layui-col-xs8 think-form-group-left">
                    <input name="photo" value='{$vo.photo|default=""}' required
                        placeholder="请上传水印照片" class="layui-input">
                </label>
                <a class="layui-col-xs4 layui-btn think-form-group-right" data-file="one"
                    data-field="photo" data-type="png,jpg,gif">
                    <i class="layui-icon layui-icon-upload"></i> 上传图片
                </a>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入备注" class="layui-textarea" name="remark">{$vo.remark|default=""}</textarea>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <blockquote class="layui-elem-quote" style="text-align: center;">物资盘点详细数据</blockquote>
        </div>
        
        <table class="layui-table">
            <colgroup>
                <col width="150">
                <col width="150">
                <col width="150">
            </colgroup>
            <thead>
                <tr>
                    <th class="text-center">商品名称</th>
                    <th class="text-center">规格</th>
                    <th class="text-center">单价</th>
                    <th class="text-center">库存</th>
                    <th class="text-center">实际库存</th>
                    <th class="text-center">差价</th>
                </tr>
            </thead>
            <tbody class="content">
                {foreach $vo.content as $key=>$v}
                <tr>
                    <td class='text-center'>{$v.name}</td>
                    <td class='text-center'>{$v.sku}</td>
                    <td class='text-center'>{$v.price}</td>
                    <td class='text-center'>{$v.count}</td>
                    <td class='text-center'>
                        <input type="number" required name="content[real_count][]" value='{$v.real_count|default=""}' oninput="myFunction(this)" placeholder="请输入实际库存" class="layui-input">
                    </td>
                    <td class='text-center diff_price'>
                        <span class="color-red"><span class="color-red">{$v.diff_price??''}</span></span>
                    </td>
                    <input type="hidden" required name="content[product_id][]" value='{$v.product_id}'>
                    <input type="hidden" required name="content[name][]" value='{$v.name}'>
                    <input type="hidden" required name="content[sku][]" value='{$v.sku}'>
                    <input type="hidden" required name="content[price][]" value='{$v.price}'>
                    <input type="hidden" required name="content[count][]" value='{$v.count}'>
                    <input type="hidden" required name="content[diff_price][]" value='{$v.diff_price??""}'>
                </tr>
                {/foreach}
            </tbody>
        </table>
    </div>
    
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
    {notempty name='Think.get.ware_house_id'}<input type='hidden' value='{$Think.get.ware_house_id}' name='ware_house_id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
</form>
<script>
    window.form.render();
    function myFunction(that) {
        var real_count = $(that).val()
        var price = $(that).parent().parent().find('input[name="content[price][]"]').val()
        var count = $(that).parent().parent().find('input[name="content[count][]"]').val()
        var diff_price = (real_count - count ) * price;
        $(that).parent().parent().find('.diff_price').html('<span class="color-red">' + diff_price + '</span>')
        $(that).parent().parent().find('input[name="content[diff_price][]"]').val(diff_price)
    }
</script>